package com.guaoran.source.mybatis.v2.mapper;

import com.guaoran.source.mybatis.bean.Demo;
import com.guaoran.source.mybatis.v2.enums.MethodTypeEnum;
import com.guaoran.source.mybatis.v2.session.SqlSession;
import lombok.Data;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : 孤傲然
 * @Description :
 * @date :2018/5/26 11:35
 */
@Data
public class MapperRegistry {
    public static Map<String,KnownMappersInfo> mappersInfoMap = new HashMap<String, KnownMappersInfo>();
    public MapperRegistry() {
        mappersInfoMap.put(
                "com.guaoran.source.mybatis.v2.mapper.DemoMapper.queryById",
                new KnownMappersInfo("select * from demo where id = ", Demo.class,
                false,
                true,
                MethodTypeEnum.SELECT
        ));
        mappersInfoMap.put(
                "com.guaoran.source.mybatis.v2.mapper.DemoMapper.queryAll",
                new KnownMappersInfo("select * from demo where 1=1 ",
                Demo.class,
                true,
                false,MethodTypeEnum.SELECT
        ));
    }

    @Data
    public static class KnownMappersInfo<E>{
        private String sql;
        private Class<E> type;
        private boolean returnMany;
        private boolean returnOne;
        private MethodTypeEnum methodType;

        public String getSql() {
            return sql;
        }

        public void setSql(String sql) {
            this.sql = sql;
        }

        public Class<E> getType() {
            return type;
        }

        public void setType(Class<E> type) {
            this.type = type;
        }

        public boolean isReturnMany() {
            return returnMany;
        }

        public void setReturnMany(boolean returnMany) {
            this.returnMany = returnMany;
        }

        public boolean isReturnOne() {
            return returnOne;
        }

        public void setReturnOne(boolean returnOne) {
            this.returnOne = returnOne;
        }

        public MethodTypeEnum getMethodType() {
            return methodType;
        }

        public void setMethodType(MethodTypeEnum methodType) {
            this.methodType = methodType;
        }

        public KnownMappersInfo(String sql, Class<E> type, boolean returnMany, boolean returnOne, MethodTypeEnum methodType) {
            this.sql = sql;
            this.type = type;
            this.returnMany = returnMany;
            this.returnOne = returnOne;
            this.methodType = methodType;
        }
    }
}
